import {BASEURL} from '@/services/api'
import {request, METHOD} from '@/utils/request'

/*
* 获取角色列表
* */
export async function getRoles(){
    return request(BASEURL+'/role/roles',METHOD.GET)
}

/*
* 根据ID获取角色信息
* */
export async function getById(id){
    return request(BASEURL+'/role/getById/'+id,METHOD.GET)
}

/*
* 添加角色信息
* */
export async function addRole(code,description){
    return request(BASEURL+'/role/addRole',METHOD.POST,{
        code:code,
        description:description
    })
}

/*
* 修改角色信息
* */
export async function updateRole(id,code,description){
    return request(BASEURL+'/role/updateRole',METHOD.POST,{
        id:id,
        code:code,
        description:description
    })
}

/*
* 根据ID删除角色信息
* */
export async function deleteById(id){
    return request(BASEURL+'/role/deleteById/'+id,METHOD.DELETE,{
        id:id
    })
}
/*
* 修改角色状态
* */
export async function updateStatus(id){
    return request(BASEURL+'/role/updateStatus/'+id,METHOD.GET,{
        id:id
    })
}
/*
* 根据角色ID查询用户列表
* */
export async function getUserByRoleId(roleId){
    return request(BASEURL+'/role/'+roleId,METHOD.GET,{
        roleId:roleId
    })
}
/*
* 分页查询所有用户
* */
export async function getUsersForRole(roleId){
    return request(BASEURL+'/user/usersByRole/'+roleId,METHOD.GET,{
        roleId:roleId
    })
}
/*
*为某一个角色添加用户
* */
export async function addUsersForRole(roleId,userIds){
    return request(BASEURL+'/role/addUsersForRole',METHOD.POST,{
        roleId:roleId,
        userIds:userIds
    })
}

/*
* 删除角色用户关联
* */
export async function deleteUserRole(roleId,userId){
    return request(BASEURL+'/userRole/deleteUserRole',METHOD.POST,{
        roleId:roleId,
        userId:userId
    })
}
